<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/template/default/commonLayout.xhtml">

	<ui:define name="content">

		<h:form id="breadCrumb">
			<p:breadCrumb>
				<p:menuitem value="#{msg['index']}" url="./index.xhtml" />
				<p:menuitem value="#{msg['courses']}" url="./course-list.xhtml" />
				<p:menuitem value="#{msg['details']}" url="#" />
			</p:breadCrumb>
		</h:form>

		<h1>
			<h:outputText value="#{msg['course.details']}" />
		</h1>

		<h:form id="form">

			<input type="hidden" name="#{_csrf.parameterName}"
				value="#{_csrf.token}" />

			<h:inputHidden id="item_id" required="false"
				value="#{courseEntityBean.item.id}" />

			<h:panelGrid id="grid" columns="3" cellpadding="4">

				<h:outputText value="#{msg['title']}" />
				<p:inputText id="item_title" required="true"
					value="#{courseEntityBean.item.title}">
					<f:validator validatorId="notEmptyValidator"
						binding="#{notEmptyValidator}" />
				</p:inputText>
				<p:message for="item_title" display="text" />

				<h:outputText value="#{msg['teacher']}" />
				<p:selectOneMenu id="item_teacher" required="true"
					value="#{courseEntityBean.item.teacher}"
					converter="teacherConverter">
					<f:selectItem itemLabel="Select One" itemValue="-1" />
					<f:selectItems value="#{teacherEntityBean.findAll()}" var="selItem"
						itemLabel="#{selItem.lastName} #{selItem.firstName}"
						itemValue="#{selItem.id}" />
				</p:selectOneMenu>
				<p:message for="item_teacher" display="text" />

			</h:panelGrid>

			<p:commandButton id="submitButton" value="#{msg['submit']}"
				update="form"
				actionListener="#{courseEntityBean.save(courseEntityBean.item)}"
				rendered="#{p:ifGranted('ROLE_ADD_COURSE') or p:ifGranted('ROLE_EDIT_COURSE') }" />

			<p:blockUI block="grid" trigger="submitButton" />

			<h:messages globalOnly="true" />

			<h:outputLink value="./course-list.xhtml">
				<h:outputText value="#{msg['back']}" />
			</h:outputLink>

		</h:form>

	</ui:define>

</ui:composition>

</html>